package domain.entities;

import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

/**
 * A data access object (DAO) providing persistence and search support for
 * ComiteEtica entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see domain.entities.ComiteEtica
 * @author MyEclipse Persistence Tools
 */

public class ComiteEticaDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(ComiteEticaDAO.class);
	// property constants
	public static final String GCPCOMPLIANCE = "gcpcompliance";
	public static final String HAS_LIST_OF_MEMBERS = "hasListOfMembers";
	public static final String LOCAL = "local";
	public static final String MEMBERS_NOT_PARTICIPATING = "membersNotParticipating";
	public static final String MEMBERS_PARTICIPATING = "membersParticipating";
	public static final String NOMBRE = "nombre";
	public static final String NOTIFICATION1ST_PATIENT_ZIEHER = "notification1stPatientZieher";
	public static final String REQUIERE_SAFETY_CASTELLANO = "requiereSafetyCastellano";
	public static final String SIGN_ALL_PAGES = "signAllPages";
	public static final String SIVNOTIFICATION_ZIEHER = "sivnotificationZieher";

	protected void initDao() {
		// do nothing
	}

	public void save(ComiteEtica transientInstance) {
		log.debug("saving ComiteEtica instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ComiteEtica persistentInstance) {
		log.debug("deleting ComiteEtica instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ComiteEtica findById(java.lang.Integer id) {
		log.debug("getting ComiteEtica instance with id: " + id);
		try {
			ComiteEtica instance = (ComiteEtica) getHibernateTemplate().get(
					"domain.entities.ComiteEtica", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<ComiteEtica> findByExample(ComiteEtica instance) {
		log.debug("finding ComiteEtica instance by example");
		try {
			List<ComiteEtica> results = (List<ComiteEtica>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ComiteEtica instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ComiteEtica as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<ComiteEtica> findByGcpcompliance(Object gcpcompliance) {
		return findByProperty(GCPCOMPLIANCE, gcpcompliance);
	}

	public List<ComiteEtica> findByHasListOfMembers(Object hasListOfMembers) {
		return findByProperty(HAS_LIST_OF_MEMBERS, hasListOfMembers);
	}

	public List<ComiteEtica> findByLocal(Object local) {
		return findByProperty(LOCAL, local);
	}

	public List<ComiteEtica> findByMembersNotParticipating(
			Object membersNotParticipating) {
		return findByProperty(MEMBERS_NOT_PARTICIPATING,
				membersNotParticipating);
	}

	public List<ComiteEtica> findByMembersParticipating(
			Object membersParticipating) {
		return findByProperty(MEMBERS_PARTICIPATING, membersParticipating);
	}

	public List<ComiteEtica> findByNombre(Object nombre) {
		return findByProperty(NOMBRE, nombre);
	}

	public List<ComiteEtica> findByNotification1stPatientZieher(
			Object notification1stPatientZieher) {
		return findByProperty(NOTIFICATION1ST_PATIENT_ZIEHER,
				notification1stPatientZieher);
	}

	public List<ComiteEtica> findByRequiereSafetyCastellano(
			Object requiereSafetyCastellano) {
		return findByProperty(REQUIERE_SAFETY_CASTELLANO,
				requiereSafetyCastellano);
	}

	public List<ComiteEtica> findBySignAllPages(Object signAllPages) {
		return findByProperty(SIGN_ALL_PAGES, signAllPages);
	}

	public List<ComiteEtica> findBySivnotificationZieher(
			Object sivnotificationZieher) {
		return findByProperty(SIVNOTIFICATION_ZIEHER, sivnotificationZieher);
	}

	public List findAll() {
		log.debug("finding all ComiteEtica instances");
		try {
			String queryString = "from ComiteEtica";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ComiteEtica merge(ComiteEtica detachedInstance) {
		log.debug("merging ComiteEtica instance");
		try {
			ComiteEtica result = (ComiteEtica) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ComiteEtica instance) {
		log.debug("attaching dirty ComiteEtica instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ComiteEtica instance) {
		log.debug("attaching clean ComiteEtica instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ComiteEticaDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (ComiteEticaDAO) ctx.getBean("ComiteEticaDAO");
	}

}